package com.kermel.andromeda.clock.view;

import com.kermel.andromeda.data.DateDisplayType;
import com.kermel.andromeda.data.settings.ClockSettings;
import com.kermel.andromeda.test.fixture.TestClockSettings;

import android.test.AndroidTestCase;
import android.widget.TextView;
import android.widget.VideoView;
import android.widget.ViewSwitcher;

public class ClockPMTest extends AndroidTestCase {
    protected static final int FIRST_CHILD_ID = 0;
    protected static final int SECOND_CHILD_ID = 1;
    
    private ClockPM clockPM;
    private ClockSettings settings;
    
    protected void setUp() throws Exception {
        super.setUp();
        
        clockPM = new ClockPM(getContext());
        
        settings = new TestClockSettings();
        clockPM.setClockSettings(settings);
        
    }

    protected void tearDown() throws Exception {
        settings = null;
        clockPM = null;
        
        super.tearDown();
    }

    public void testIsDateDisplayedWhenSettingsIsFalse() {
        ((TestClockSettings)settings).setDisplayDate(false);
        assertFalse(clockPM.isDateDisplayed());
    }

    public void testIsDateDisplayedWhenSettingsIsTrue() {
        ((TestClockSettings)settings).setDisplayDate(true);
        assertTrue(clockPM.isDateDisplayed());
    }

    public void testIsFullDateDisplayedWhenSettingsIsFalse() {
        ((TestClockSettings)settings).setDisplayDate(false);
        assertFalse(clockPM.isFullDateDisplayed());
        
        ((TestClockSettings)settings).setDisplayDate(true);
        ((TestClockSettings)settings).setDateDisplayType(DateDisplayType.SHORT);
        assertFalse(clockPM.isFullDateDisplayed());
    }

    public void testIsFullDateDisplayedWhenSettingsIsTrue() {
        ((TestClockSettings)settings).setDisplayDate(true);
        ((TestClockSettings)settings).setDateDisplayType(DateDisplayType.FULL);
        assertTrue(clockPM.isFullDateDisplayed());
    }

    public void testIsShortDateDisplayedWhenSettingsIsFalse() {
        ((TestClockSettings)settings).setDisplayDate(false);
        assertFalse(clockPM.isShortDateDisplayed());
        
        ((TestClockSettings)settings).setDisplayDate(true);
        ((TestClockSettings)settings).setDateDisplayType(DateDisplayType.FULL);
        assertFalse(clockPM.isShortDateDisplayed());
    }

    public void testIsShortDateDisplayedWhenSettingsIsTrue() {
        ((TestClockSettings)settings).setDisplayDate(true);
        ((TestClockSettings)settings).setDateDisplayType(DateDisplayType.SHORT);
        assertTrue(clockPM.isShortDateDisplayed());
    }
    
    public void testThatTheFullDateIsDisplayedWhenSettingsIsFullDateDisplay() {
        ((TestClockSettings)clockPM.getClockSettings()).setDisplayDate(true);
        ((TestClockSettings)clockPM.getClockSettings()).setDateDisplayType(DateDisplayType.FULL);
        
        ViewSwitcher dateViewSwitcher = new ViewSwitcher(getContext());
        dateViewSwitcher.addView(new TextView(getContext()));
        dateViewSwitcher.addView(new VideoView(getContext()));
        
        clockPM.switchTypeOfDateDisplayBasedOnSettings(dateViewSwitcher);
        int viewID = dateViewSwitcher.getDisplayedChild();
        
        assertEquals(FIRST_CHILD_ID, viewID);
    }
    
    public void testThatTheShortDateIsDisplayedWhenSettingsIsShortDateDisplay() {
        ((TestClockSettings)clockPM.getClockSettings()).setDisplayDate(true);
        ((TestClockSettings)clockPM.getClockSettings()).setDateDisplayType(DateDisplayType.SHORT);
        
        ViewSwitcher dateViewSwitcher = new ViewSwitcher(getContext());
        dateViewSwitcher.addView(new TextView(getContext()));
        dateViewSwitcher.addView(new VideoView(getContext()));
        
        clockPM.switchTypeOfDateDisplayBasedOnSettings(dateViewSwitcher);
        int viewID = dateViewSwitcher.getDisplayedChild();
        
        assertEquals(SECOND_CHILD_ID, viewID);
    }

}
